package ifmo.compiler.task21.lexer.tokens;

import ifmo.compiler.task21.entity.RationalNumber;

/**
 * @author byaminov
 */
public class Rational extends Token<RationalNumber> {

    private RationalNumber r;

    protected Rational(String value) {
        super(TokenType.RATIONAL);
        String[] parts = value.split("/");
        if (parts.length != 2) {
            throw new IllegalArgumentException("String value for Rational could not be parsed " +
                    "(splitting by '/' gave not 2 parts): " + value);
        }
        int numerator = Integer.parseInt(parts[0].trim());
        int denominator = Integer.parseInt(parts[1].trim());
        r = new RationalNumber(numerator, denominator);
    }

    public RationalNumber getValue() {
        return r;
    }
}
